local sk__anguo = fk.CreateSkill {

  name = "sk__anguo",

  tags = {  },

}



sk__anguo:addEffect(fk.DrawNCards, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__anguo.name) and data.n > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#sk__anguo-choose", sk__anguo.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.n = data.n - 1
    local to = room:getPlayerById(event:getCostData(self))
    local yes = true
    while not to.dead and yes do
      local cards = table.filter(room.draw_pile, function(id)
        local card = Fk:getCardById(id)
        return card.type == Card.TypeEquip and not to:isProhibited(to, card)
      end)
      if #cards == 0 then return end
      local card = Fk:getCardById(table.random(cards))
      room:useCard{
        from = to,
        card = card,
      }
      if to.dead then return end
      if card.sub_type == Card.SubtypeWeapon then
        to:drawCards(card.attack_range, sk__anguo.name)
        yes = false
      elseif card.sub_type == Card.SubtypeArmor or card.sub_type == Card.SubtypeTreasure then
        if to:isWounded() then
          room:recover{
            who = to,
            num = 1,
            recoverBy = player,
            skillName = sk__anguo.name,
          }
        end
        yes = false
      else
        yes = true
      end
    end
  end,
})

return sk__anguo